package com.lingyi.algorithm.lab5;

/**
 * @author chenweilong
 * @email 1433471850@qq.com
 * @date 2020-08-21 10:01
 */
public class BFMatch {

    public static void main(String[] args) {

        int sub = 0;


        String mString = "defdeldemdesddmdes";

        String subString  = "des";


        char[] mChars = mString.toCharArray();

        char[] subChars = subString.toCharArray();


        int i = 0;

        int j = 0;

        System.out.println(mChars.length);
        System.out.println(subChars.length);



        while (i < mChars.length && j < subChars.length) {

            sub++;
            if (mChars[i] == subChars[j]) {
                j++;
                i++;
            }else {
                i = (i - j) + 1;
                j = 0;
            }
        }

        System.out.printf("一共运行的次数%s\n",sub);

        if (j == subChars.length) {
            System.out.println(i - j);
        }else {
            System.out.println(-1);
        }

    }

}
